#include "tabu_pfs.h"
#include <omp.h>

Tabu_PFS::Tabu_PFS(const PFS_Item& pfs_item, double time_limit,
		int neighbor_per_time, int retry_limit, size_t tubu_list_len)
	: II_PFS(pfs_item, time_limit, neighbor_per_time, retry_limit),
		tabu_list_(tubu_list_len) {}

void Tabu_PFS::FindBestNeighbor(const Solution& solution,
		int* score_now, Solution* next_solution) {

	int best_score = kWorstScore;

	#pragma omp parallel for
	for (int i = 0 ; i < neighbor_per_time() ; ++i) {
		Solution neighbor = GetNeighbor(solution);
		int neighbor_score = Score(neighbor);
		if (neighbor_score > best_score && !tabu_list_.Has(neighbor)) {

			#pragma omp critical
			{
				if (neighbor_score > best_score && !tabu_list_.Has(neighbor)) {
					best_score = neighbor_score;
					*next_solution = std::move(neighbor);
				}
			}

		}
	}
}

void Tabu_PFS::SolutionGo(Solution* solution, const Solution next_solution) {
	*solution = next_solution;
	tabu_list_.Push(next_solution);
}
